package com.cby.project.mvi

import android.app.Application
import com.cby.android.olive.CbyOliveTools
import com.cby.project.mvi.data.UserApi
import com.cby.project.mvi.data.UserApiSource
import com.cby.project.mvi.flow.FlowViewModel
import com.cby.project.mvi.model.UserViewModel
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.context.GlobalContext.startKoin
import org.koin.core.logger.Level
import org.koin.dsl.module

/**
 * @description: MviApplication
 *
 * @author ChenBaoyang
 * @date 2021/11/29 17:56
 */
class MviApplication : Application() {

    private val mviAppModule = module {
        single<UserApi> { UserApiSource() }
        viewModel { UserViewModel(get()) }
        viewModel { FlowViewModel() }
    }

    override fun onCreate() {
        super.onCreate()
        CbyOliveTools.init(this@MviApplication)
        startKoin {
            androidLogger(Level.DEBUG)
            androidContext(androidContext = this@MviApplication)
            modules(mviAppModule)
        }
    }
}